package com.rc.saas.tenant.controller.elec;

import com.rc.saas.tenant.client.ChargerClientRouter;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by sven on 2019/10/24
 */
@RestController
@RequestMapping("/client")
public class MicroServiceController {
    private static Logger logger = LogManager.getLogger(MicroServiceController.class);

    @Autowired
    private ChargerClientRouter chargerClientRouter;

    //@Autowired
    //private LoadBalancerClient loadBalancerClient;

    //@GetMapping("/getPoducerInfo")
    //public String getPoducerInfo() {
    //    //协议http+服务名（即application.yml配置spring.application.name的值）+接口值
    //    String result = restTemplate.getForObject("http://springcloud-eureka-server/getPoducerInfo/" + 333, String.class);
    //    return result;
    //}

    /**
     * http://localhost:8081/client/test/3
     * @param id
     * @return
     */
    @GetMapping("/test/{id}")
    public String test(@PathVariable Long id) {
        try {
            String aa = chargerClientRouter.test("AAA", id);
            logger.info("EurekaClientRouter 调用成功:{}", aa);
            return aa;
        } catch (Exception e) {
            logger.error("EurekaClientRouter 调用失败", e);
        }

        return null;
    }

    /**
     * http://localhost:8181/client/query_start_charge
     */
    //@GetMapping("/query_start_charge")
    //public void query_start_charge() {
    //    try {
    //        ObjectMapper objectMapper = new ObjectMapper();
    //        CommandStartReq chargeRequestVo = new CommandStartReq();
    //        chargeRequestVo.setElecPileId(111L);
    //        chargeRequestVo.setMemberId(111L);
    //        //chargeRequestVo.setStatus("2");
    //        chargeRequestVo.setGunNum("111");
    //        //chargeRequestVo.setOrderId(null);
    //        chargeRequestVo.setChargeType("1");
    //        chargeRequestVo.setTenantCode("888");
    //        String respData = objectMapper.writeValueAsString(chargeRequestVo);
    //        //加密
    //        String jsonData = encryptData(respData);
    //        TRequest tRequest = genSuccessReq(jsonData, tenantConfig.getTenantCode());
    //        TResponse tResponse = eurekaClientFeignA.query_start_charge(tRequest);
    //    } catch (Exception e) {
    //        logger.error("发送启动充电指令失败", e);
    //    }
    //}

    //@GetMapping("/log-instance")
    //public void logUserlnstance() {
    //    ServiceInstance serviceInstance = loadBalancerClient.choose("springcloud-eureka-server");
    //    //打印当前选择的是哪个节点
    //    logger.info("打印当前选择的是哪个节点:{}:{}:{}", serviceInstance.getServiceId(), serviceInstance.getHost(), serviceInstance.getPort());
    //}

}
